<?
/*
 * 资讯频道栏目递归
 */
class Zixuntype {
    
	/*
	* 读取递归数据的方法数，使用前请把digui()函数的返回值进行缓存
	* @param array $list 这个参数是S('zixuntype')读取过来的层级关系的多维数组，是由digui()产生的
	* @return void 无返回值直接输出
	*/
	function tree($list){
		foreach ($list as $k => $v) {
			 echo '<tr align="center"  bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>'.$v['id'].'</td><td width="14%"><a href="__GROUP__/Archive/index/typeid/'.$v['id'].'">'.$v['typename'].' ('.$this->get_zixunnum($v['id']).')</a></td><td width="14%">'.$v['sort'].'</td><td><a class="coolbg" href="'.U('Home/Arctype/index',array('id'=>$v['id'])).'" target="_blank">预览</a>&nbsp;&nbsp;<span class="coolbg" onClick="winopen(\'__URL__/edit/id/'.$v['id'].'\',\'id'.$v['id'].'\',1000,650)">修改</span>&nbsp;&nbsp;<a href="__URL__/del/id/'.$v['id'].'" class="coolbg" onClick="return confirm(\'你确定要删除该记录吗？\');">删除</a></td></tr>';
			 $this->treeSeed($v['childs']);
		 } 
	}
        
	/*
	* 递归子级
	*/    
	function treeSeed($list){
		if($list){
			echo '<tr align="center"  bgcolor="#FFFFFF" height="22" class="seed"><td colspan="4"><table width="98%">';
			foreach ($list as $k => $v) {
				 echo '<tr align="center"  bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>'.$v['id'].'</td><td width="14%"><a href="__GROUP__/Archive/index/typeid/'.$v['id'].'">'.$v['typename'].' ('.$this->get_zixunnum($v['id']).')</a></td><td width="14%">'.$v['sort'].'</td><td><a class="coolbg" href="'.U('Home/Arctype/index',array('id'=>$v['id'])).'" target="_blank">预览</a>&nbsp;&nbsp;<span class="coolbg" onClick="winopen(\'__URL__/edit/id/'.$v['id'].'\',\'id'.$v['id'].'\',1000,650)">修改</span>&nbsp;&nbsp;<a href="__URL__/del/id/'.$v['id'].'" class="coolbg" onClick="return confirm(\'你确定要删除该记录吗？\');">删除</a></td></tr>';
				 $this->treeSeed($v['childs']);
			 }
			echo '</table></td></tr>';
		}
	}
	
	
	/*
	 * 取得资讯频道 当前栏目有多少篇文章
	 */
	function get_zixunnum($typeid){
		//取得当前栏目的模型
		$m = M('arctype');
		$list = $m->field('channel.*')
				  ->join('channel on channel.id=arctype.channelid')->where(array('zixuntype.id'=>$typeid))->find();
		if($list['modeltype'] == 3){
			$m2 = M($list['tablename']);
			$num = $m2->where(array('typeid'=>$typeid))->count();
		}else{
			$m2 = M('archive');
			$num = $m2->where(array('typeid'=>$typeid))->count();	
		}		
		return $num;
	}

}